<template>
  <div class="app-container">
    <!--工具栏-->
    <div>
      <el-form ref="queryForm" :inline="true" label-width="80px">
        <el-row>
          <!--          <el-form-item label="系统名">-->
          <!--            <el-select v-model="query.system" placeholder="请选择系统名" clearable style="width:190px">-->
          <!--              <el-option v-for="val in systemName" :key="val" :label="val" :value="val" />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item label="库名">
            <el-input v-model="query.schemaName" placeholder="请输入库名" @keyup.enter.native="crud.toQuery" />
          </el-form-item>
          <el-form-item label="表名">
            <el-input v-model="query.tableName" placeholder="请输入表名" @keyup.enter.native="crud.toQuery" />
          </el-form-item>
          <!--          <el-form-item label="系统日期">-->
          <!--            <el-date-picker-->
          <!--              v-model="query.systemTime"-->
          <!--              type="date"-->
          <!--              placeholder="请选择日期"-->
          <!--              value-format="timestamp">-->
          <!--            </el-date-picker>-->
          <!--          </el-form-item>-->
          <el-form-item label="发送级别">
            <el-select v-model="query.sendRank" placeholder="请选择" filterable clearable style="width:190px">
              <el-option v-for="val in dict.dqc_submit_level" :key="val.id" :label="val.label" :value="val.value" />
            </el-select>
          </el-form-item>
          <!--          <el-form-item label="规则编码">-->
          <!--            <el-input v-model="query.scriptName" placeholder="请输入编码规则" />-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="执行方式">-->
          <!--            <el-select v-model="query.method" placeholder="请选择" clearable style="width:190px">-->
          <!--              <el-option v-for="val in dict['dqc_execute_method_list']" :key="val.id" :label="val.label" :value="val.value" />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item label="检查频率">
            <el-radio-group v-model="query.inspectFrequency">
              <el-select v-model="query.inspectFrequency" placeholder="请选择" filterable clearable style="width:190px">
                <el-option v-for="(label, value) in inspectFrequencyOptions" :key="value" :label="label" :value="value" />
              </el-select>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="校验状态">
            <el-select v-model="query.status" placeholder="请选择" filterable clearable style="width:190px">
              <el-option v-for="(label, value) in statusOptions" :key="value" :label="label" :value="value" />
            </el-select>
          </el-form-item>
          <!--          <el-form-item label="通知时间">-->
          <!--            <el-date-picker-->
          <!--              v-model="notifyTime"-->
          <!--              type="date"-->
          <!--              placeholder="请选择日期">-->
          <!--            </el-date-picker>-->
          <!--          </el-form-item>-->
          <rrOperation :crud="crud" />
        </el-row>
      </el-form>
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      style="width: 100%;"
      :data="crud.data"
      @filter-change="crud.handleFilterChange"
      @select="crud.selectChange"
      @select-all="crud.selectAllChange"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column v-if="columns.visible('systemName')" label="系统名" prop="systemName" />
      <!-- <el-table-column v-if="columns.visible('jobName')" label="作业名" prop="jobName" /> -->
      <el-table-column v-if="columns.visible('tableName')" label="表名" prop="tableName" min-width="150" />
      <el-table-column v-if="columns.visible('schemaName')" label="库名" prop="schemaName" min-width="150" />
      <!--      <el-table-column v-if="columns.visible('ruleEncode')" prop="ruleEncode"  label="规则编码"></el-table-column>-->
      <el-table-column v-if="columns.visible('runMode')" prop="runMode" label="执行方式">
        <template slot-scope="scope">
          {{ formatterRunMode(scope.row.runMode) }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns.visible('sendRank')" prop="sendRank" label="发送级别">
        <template slot-scope="scope">
          {{ formatterSendRank(scope.row.sendRank) }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns.visible('inspectFrequency')" label="检查频率" prop="inspectFrequency">
        <template slot-scope="scope">
          {{ formatterInspectFrequency(scope.row.inspectFrequency) }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns.visible('systemTime')" label="系统时间" prop="systemTime" min-width="150" />
      <el-table-column v-if="columns.visible('finishTime')" label="通知时间" prop="finishTime" min-width="150" />
      <el-table-column v-if="columns.visible('content')" label="消息内容" prop="content" min-width="300px" />
      <el-table-column v-if="columns.visible('status')" label="校验状态" prop="status">
        <template slot-scope="scope">
          {{ formatterStatus(scope.row.status) }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import pagination from '@crud/Pagination.vue'
import dqcConfigApi from '@/api/dqc/dqcConfig'

// crud交由presenter持有
const defaultCrud = CRUD({ title: 'DQC日志审计', url: '/api/dqc/task/log', crudMethod: { ...dqcConfigApi }})
const defaultForm = {
  pkId: null,
  taskPkId: null,
  jobName: '',
  systemName: '',
  schemaName: '',
  tableName: '',
  ruleEncode: '',
  runMode: null,
  sendRank: null,
  inspectFrequency: null,
  systemTime: '',
  finishTime: '',
  content: '',
  status: '',
  crtUser: null,
  crtUserName: null,
  crtTs: null
}
export default {
  name: 'DqcLog',
  components: {
    rrOperation,
    pagination
  },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['dqc_execute_method_list', 'dqc_submit_level'],
  data() {
    return {
      statusOptions: {
        success: '成功',
        fail: '失败'
      },
      inspectFrequencyOptions: {
        day: '每日',
        season: '每季',
        year: '每年'
      }
    }
  },
  created() {
    this.crud.resetQuery(false)
  },
  methods: {
    formatterSendRank(val) {
      return this.dict.label.dqc_submit_level[val]
    },
    formatterRunMode(val) {
      return this.dict.label.dqc_execute_method_list[val]
    },
    formatterInspectFrequency(val) {
      if (val === 'day') {
        return '每日'
      }
      if (val === 'season') {
        return '每季'
      }
      if (val === 'year') {
        return '每年'
      }
    },
    formatterStatus(val) {
      if (val === 'success') {
        return '校验成功'
      }
      if (val === 'fail') {
        return '校验失败'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>

